
from flask import Flask


def register_web_blueprint(app):
    # 将 flask app api 注册到蓝图中

    from app.api import api
    app.register_blueprint(api)


def create_app(config=None):
    """
    创建 flask app
    :param config:
    :return:
    """
    app = Flask(__name__)

    # 加载配置
    app.config.from_object('app.secure')
    # 初始化数据库
    # db.init_app(app)

    # 注册蓝图
    register_web_blueprint(app)

    if config is not None:
        if isinstance(config, dict):
            app.config.update(config)
        elif config.endswith('.py'):
            app.config.from_pyfile(config)
    return app
